package com.example.demo.util;

import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;

/**
 * @author: zyc
 */
public class Shell {

    String  username;
    String  password;
    String  host;
    int     port;
    final static JSch    jSch = new JSch();
    Session session;

    public Shell(String username, String password, String host, int port) {
        this.username = username;
        this.password = password;
        this.host = host;
        this.port = port;
        try {
            session = jSch.getSession(username, host, port);
            session.setPassword(password);
            session.setConfig("StrictHostKeyChecking", "no");//去掉连接确认的
            session.connect(10000);
        } catch (JSchException e) {
            e.printStackTrace();
            throw new RuntimeException("创建session失败");
        }
    }

    public static void main(String[] args) {

    }
}
